package com.project.oauth2Server.controller.business;

import com.project.annotation.model.UserConfig;
import com.project.annotation.model.base.RequestBase;
import com.project.annotation.model.base.ResultBase;
import com.project.annotation.model.base.VoidResult;
import com.project.oauth2Server.config.ClientConfig;
import com.project.oauth2Server.model.AccessTokenInfo;
import com.project.oauth2Server.model.TokenInfo;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.Principal;

@RequestMapping("/oauth")
public interface OAuth2CtrlInterface {

    @PostMapping("/registerClient")
    void registerClient(@RequestBody ClientConfig config);

    @PostMapping("/refreshToken")
    ResultBase<AccessTokenInfo> refreshToken(
            HttpServletRequest request, HttpServletResponse response,
            @RequestParam("client_id") String client_id,
            @RequestParam("client_secret") String client_secret,
            @RequestParam("refresh_token") String refresh_token) throws Exception;

    @PostMapping("/logout")
    ResultBase logout(@RequestParam("token") String token);

    @PostMapping("/login")
    ResultBase<AccessTokenInfo> login(
            HttpServletRequest request, HttpServletResponse response,
            @RequestParam("code") String code,
            @RequestParam("client_id") String client_id,
            @RequestParam("client_secret") String client_secret,
            @RequestParam("redirect_uri") String redirect_uri
    );

    @PostMapping("/info")
    ResultBase<TokenInfo> info(@RequestParam("token") String token);

    @PostMapping("/createUserInfo")
    ResultBase<VoidResult> createUserInfo(@RequestBody UserConfig item);

    @PostMapping("/check")
    ResultBase<Boolean> check(@RequestParam("token") String token);

    @GetMapping("/callback")
    ResultBase<String> callback(@RequestParam("code") String token, Principal principal);
}
